document.addEventListener('DOMContentLoaded', function() {
  let userRole = sessionStorage.getItem('userRole');
  let username = sessionStorage.getItem('username');
  if (!userRole || !username) {
    // 游客未登录：只显示guest-only，隐藏user-only和admin-only
    document.querySelectorAll('.admin-only, .user-only').forEach(el => el.style.display = 'none');
    document.querySelectorAll('.guest-only').forEach(el => el.style.display = '');
    return;
  }
  if (userRole === 'registered') {
    // 隐藏仅管理员可见
    document.querySelectorAll('.admin-only').forEach(el => el.style.display = 'none');
  } else if (userRole === 'guest') {
    // 隐藏注册用户和管理员功能
    document.querySelectorAll('.admin-only, .user-only').forEach(el => el.style.display = 'none');
  }
  // admin全部可见，无需隐藏
}); 